/**
 * @(#) CongMoney2ListProxy.as
 *
 * @date		2009. 03. 19.
 * @version		1.0
 * @author		Park, Juneho
 * @description	 경조사 Proxy - Proxy
 * 				경조사 조회를한다.
 */
package com.skt.common_hr.congmoney2.model
{
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.skt.common_hr.congmoney2.model.vo.CongMoneyListVO;
	import com.wcl.dataloader.*;
	import com.wcl.utils.DateUtil;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
		
	public class CongMoney2ListProxy extends CommonProxy
	{
		public static const NAME:String = "CongMoney2ListProxy";

		public static const LOAD_CONGMONEY_LIST_COMPLETE:String = "loadCongMoneyListComplete";
		public static const LOAD_CONGMONEY_LIST_FAILED:String = "loadCongMoneyListFailed";
		public static const LOAD_CONGMONEY_PRINT_COMPLETE:String = "loadCongmoneyPrintComplete";
		
		
		public var congMoneyList:ArrayCollection;
		
		/**
		 * 생성자
		 * 
		 * @param
		 * @return void
		 */
		public function CongMoney2ListProxy(data:Object=null)
		{
			super(NAME, data); 
		}
		
		
		
		/**
		 * data load를 수행
		 * 		- DataLoader 를 생성하고 Import Parameter 객체를 생성, RFC를 호출
		 * 
		 * @param pernr 사번
		 * @return void
		 */
		public function loadList(pernr:String, beg:Date, end:Date, status:String):void
		{
			var params:Object = new Object();
			params["I_PERNR"] = pernr;
			params["I_BEGDA"] = DateUtil.toBasicString(beg);
			params["I_ENDDA"] = DateUtil.toBasicString(end);
			params["I_WSTATUS"] = status;
			
			loadData("Z_HR_0045_G", params, listResult, listFault);
		}
		
		
		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event Listeners
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 경조금 신청 리스트가 정상적으로 로드되었을  때 처리
		 * 
		 * @param
		 * @return void
		 */
		public function listResult(event:ResultEvent):void
		{
			if(retCode==0) {  
				congMoneyList = parseCongMoneyList(event.result.FTAB);
				facade.sendNotification(LOAD_CONGMONEY_LIST_COMPLETE, this);
			}
			else {
				facade.sendNotification(LOAD_CONGMONEY_LIST_FAILED, this);
			}
		}
		
		/**
		 * 경조금 신청 리스트가 실패 했을 때 처리
		 * 
		 * @param
		 * @return void
		 */
		private function listFault(event:FaultEvent):void
		{
			facade.sendNotification(LOAD_CONGMONEY_LIST_FAILED, this);
		}
		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Data Parsing functions
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 전달된 result 객체를 분석하여 Value Object를 생성
		 * 
		 * @param
		 * @return 경조사조회 현황 ArrayCollection
		 */
		private function parseCongMoneyList(srcArr:ArrayCollection):ArrayCollection
		{
			var retArr:ArrayCollection = new ArrayCollection();
			
			for each(var rec:Object in srcArr) 
			{
				var vo:CongMoneyListVO = new CongMoneyListVO();
				
				vo.GWAREKEY		= rec["GWAREKEY"];		//Groupware 전자결재 Key
				vo.IDATE		= DateUtil.stringToDateTime(rec["IDATE"]);			//신청일
				vo.CODAT		= DateUtil.stringToDateTime(rec["CODAT"]);			//경조발생일
				vo.CORSN		= rec["CORSN"];			//경조사유 코드
				vo.ZTEXT		= rec["ZTEXT"];			//경조내역
				vo.CPERNR		= rec["CPERNR"];		//경조대상자 사원 번호
				vo.CNAME		= rec["CNAME"];			//대상자이름
				vo.BNKSA		= rec["BNKSA"];			//은행 계정 정보 레코드 유형
				vo.STEXT		= rec["STEXT"];			//계좌구분
				vo.WSTATUS		= rec["WSTATUS"];		//결재진행상태
				vo.WSTATX		= rec["WSTATX"];		//결재진행상태텍스트
				vo.BSTATUS		= rec["BSTATUS"];		//전표진행상태
				vo.BSTATX		= rec["BSTATX"];		//전표진행상태
				vo.COBEG		= DateUtil.stringToDateTime(rec["COBEG"]);	
				vo.COEND		= DateUtil.stringToDateTime(rec["COEND"]);	
				vo.CNNCT		= rec["CNNCT"];		// 연락처
				vo.COPER		= rec["COPER"];		//사유발생자

				retArr.addItem(vo);
			}
			return retArr;	
		}
		
	}
}